package cn.jiahua.hospital.service.impl;

import cn.jiahua.hospital.dto.*;
import cn.jiahua.hospital.mapper.DoctorMapper;
import cn.jiahua.hospital.pojo.Doctor;
import cn.jiahua.hospital.pojo.Hospital;
import cn.jiahua.hospital.service.DoctorService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

import cn.jiahua.hospital.constants.Constants;

import javax.annotation.Resource;

@Service
public class DoctorServiceImpl implements DoctorService {

    @Resource
    private DoctorMapper doctorMapper;

    @Override
    public Doctor getDoctorById(Integer id) {
        return doctorMapper.getDoctorById(id);
    }

    @Override
    public DoctorDto getDoctor(Integer id) {
        return doctorMapper.getDoctor(id);
    }

    @Override
    public List<Doctor> getDoctorListByMap(Map<String, Object> param) {
        return doctorMapper.getDoctorListByMap(param);
    }

    @Override
    public List<DoctorDto> searchDocotr(Map<String, Object> param) {
        return  doctorMapper.searchDocotr(param);
    }

    @Override
    public List<Hospital> searchHospital(Map<String, Object> param) {
        return doctorMapper.searchHospital(param);
    }

    @Override
    public List<TdepartmentsDto> searchTdepartments(Map<String, Object> param) {
        return doctorMapper.searchTdepartments(param);
    }

    @Override
    public Integer getDoctorCountByMap(Map<String, Object> param) {
        return doctorMapper.getDoctorCountByMap(param);
    }

    @Override
    public Integer qdtxAddDoctor(DoctorDto doctor) {
        return doctorMapper.insertDoctor(doctor);
    }

    @Override
    public String exist(String exist) {
        return doctorMapper.exist(exist);
    }

    @Override
    public Integer qdtxModifyDoctor(Doctor doctor) {
        return doctorMapper.updateDoctor(doctor);
    }

    @Override
    public Integer updateDoctor_pic(DoctorDto doctorDto) {
        return doctorMapper.updateDoctor_pic(doctorDto);
    }



    @Override
    public Integer qdtxDeleteDoctorById(Integer id) {
        return doctorMapper.deleteDoctorById(id);
    }

    @Override
    public Integer qdtxBatchDeleteDoctor(String ids) {
        Map<String, List<String>> param = new HashMap<String, List<String>>();
        String[] paramArrays = ids.split(",");
        List<String> idList = new ArrayList<String>();
        for (String temp : paramArrays) {
            idList.add(temp);
        }
        param.put("ids", idList);
        return doctorMapper.batchDeleteDoctor(param);
    }

    @Override
    public Page<Doctor> queryDoctorPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = doctorMapper.getDoctorCountByMap(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<Doctor> doctorList = doctorMapper.getDoctorListByMap(param);
        page.setList(doctorList);
        return page;
    }

    @Override
    public List<DoctorDto> getDoctorList(Map<String, Object> param) {
        return doctorMapper.getDoctorList(param);
    }

    @Override
    public Integer getDoctorCount(Map<String, Object> param) {
        return doctorMapper.getDoctorCount(param);
    }

    @Override
    public List<DoctorDto> getDoctorList1(Map<String, Object> param) {
        return doctorMapper.getDoctorList1(param);
    }

    @Override
    public Integer getDoctorCount1(Map<String, Object> param) {
        return doctorMapper.getDoctorCount1(param);
    }


    @Override
    public Integer updateForbidden(Integer id, Integer state) throws DoctorExtion {
        return doctorMapper.updateForbidden(id, state);
    }

    @Override
    public Page<Doctor> getDoctorListlimit(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = doctorMapper.getDoctorCountByMap(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<Doctor> doctorList = doctorMapper.getDoctorListByMap(param);
        page.setList(doctorList);
        return page;
    }

    @Override
    public List<Doctor> doctorSubscribeData(Integer pageNo, Integer pageSize) {
        return doctorMapper.doctorSubscribeData(pageNo,pageSize);
    }

    @Override
    public List<PageDoctorDto> getDoctorPageInfo(Integer doctorId,Integer hospitalId,Integer tdepartmentsId) throws Exception {
        return doctorMapper.getDoctorPageInfo(doctorId,hospitalId,tdepartmentsId);
    }

    @Override
    public List<DoctorDto> gettDepartmentsDoctor(Integer dieseaseId, Integer hospitalId, Integer doctorId) throws Exception {
        return doctorMapper.gettDepartmentsDoctor(dieseaseId,hospitalId,doctorId);
    }

    @Override
    public List<Integer> getDoctorByCondition(Integer hospitalId, String name) throws Exception {
        return doctorMapper.getDoctorByCondition(hospitalId,name);
    }

}